<?php

namespace App\Http\Controllers\Test;

use App\Http\Controllers\Controller;
use App\Models\Admin;
use App\Models\Article;
use App\Models\SiteWechat;
use App\Models\Tag;
use App\Models\User;
use App\Models\UserModify;
use App\Models\UserVerify;
use App\Service\Ip;
use Illuminate\Support\Facades\DB;


class TestController extends Controller
{
    // 测试
    public function initialize()
    {
        parent::initialize();
    }

    // 取消html标签
    // option.com/test/test/html
    public function html()
    {
        $_rangeHtml = '<p style="padding: 3px 0;"><img style="max-width:98%;" src="https://slh.caitongnews.com/caiji/weixin/2023/202309/20/202309201695178901.5876701338070.jpg"></p><p style="padding: 3px 0;">印度的市场确实很香，但汽车作为大众消费品，对人群购买力的要求要远高于手机这类普通消费品，需要更为长期的兑现期。</p>';
        $_rangeHtml = strip_tags($_rangeHtml, '<img>');
        echo $_rangeHtml;
    }

    // 测试正则包含
    // option.com/test/test/reg
    public function reg()
    {
        $_title   = '【易见3】易见3:董事、监事换届选举公告';
        $_keyword = '易见';
        $is_match = preg_match('/【.*?'.$_keyword.'.*?】/', $_title);

        var_dump($is_match);
    }


    // 测试远程图片是否存在
    public function image()
    {
        $url = 'http://tp2.sinaimg.cn/1652845545/50/5679800235/1';
        $url = 'http://qzapp.qlogo.cn/qzapp/100232596/F6145BC9A088532FFAEE2CB8BE804EB1/100';
        $nr  = file_get_contents($url);

        var_dump($nr);

        return $this->success([$nr]);
    }

    // 用户查询单条记录
    public function user()
    {
        $field = $this->userField();
        $uids  = [2, 7, 8, 9, 10, 13, 15, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30];
        $uids  = [10008, 10009, 10010, 10011, 10012, 10013, 10014, 10015, 10016, 10017, 10018, 10019, 10020, 10021, 10022, 10023, 10024,];
        $lists = (new User())->isCache(true)->getListInIds($uids, $field);

        //$lists = (new User())->isCache(true)->getOneById(20, $field);

        return $this->success($lists);
    }

    // 删除二维数组最后一个元素
    public function del()
    {
        $data = (new Admin())->getAll();
        var_dump($data);
        echo '<br/>';
        echo '<br/>';
        echo '<br/>';
        echo '<br/>';
        array_pop($data);
        var_dump($data);
        echo '<br/>';
        echo '<br/>';
        echo '<br/>';
        echo '<br/>';

    }

    // 测试
    // http://www.slh.com/test/test/test
    public function test()
    {
        // 关联数组，不能使用 ... 符号
        $data = ['in' => 'aa', 'my' => 'bb', 'cd' => 'cc'];
        var_dump($data);

        $data = ['aa', 'bb', 'cc'];
        var_dump(...$data);
        echo $this->func(...$data);
    }

    // 引入组件
    public function func($a, $b, $c)
    {
        $str = '$a+2*$b+3$c = '."$a+2*$b+3$c";

        return $str;
    }

}


